/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;

/**
 * <p>Project: jse2204 - NumberFormat1
 * <p>Powered by webrx On 2022-08-30 14:33:28
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class NumberFormat1 {
    public static void main(String[] args) {
        //百分比
        NumberFormat f1 = NumberFormat.getPercentInstance();
        System.out.println(f1.format(.235));//24%

        var f2 = NumberFormat.getPercentInstance();
        //f2.setMaximumFractionDigits(2);
        //System.out.println(f2.format(.23558));//23.56%

        f2.setMinimumFractionDigits(4);
        System.out.println(f2.format(.23558));//23.5580%


        //Locale.setDefault(Locale.JAPAN);
        var m = 60;
        var f3 = NumberFormat.getCurrencyInstance();
        System.out.println(f3.format(m));


        var f4 = NumberFormat.getNumberInstance();
        f4.setMinimumFractionDigits(2);
        System.out.println(f4.format(1242450.512346)); //1,242,450.512

        var f5 = NumberFormat.getCompactNumberInstance();
        System.out.println(f5.format(123424l));//12万

        DecimalFormat df = new DecimalFormat("#,###.##");

        //设置四舍五入模式，RoundingMode.DOWN RoundingMode.CEILING
        df.setRoundingMode(RoundingMode.DOWN);
        System.out.println(df.format(100.12178));

    }
}
